home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / chunker / source / machine.c < prev    next >
C/C++ Source or Header  |  1995-11-15  |  4KB  |  194 lines

  1. /*************************************************************************
  2.  *
  3.  * Chunker/DeChunk
  4.  *
  5.  * Copyright ©1995 Lee Kindness and Evan Tuer
  6.  * cs2lk@scms.rgu.ac.uk
  7.  *
  8.  * machine.c
  9.  *  Initilisation code plus any other machine dependant code.
  10.  */
  11.  
  12. #include "machine.h"
  13.  
  14.  
  15. #ifdef AMIGA
  16.  
  17. /*************************************************************************
  18.  * msprintf() - Equivalent to sprintf(). Implemented using the exec RawDoFmt
  19.  *  command. Note that "\x16\xC0\x4E\x75" represents:
  20.  *
  21.  *    move.b  d0,(a3)+
  22.  *    rts
  23.  */
  24.  
  25. void msprintf(char *buffer, char *format, ...)
  26. {
  27.     RawDoFmt(format, (APTR)(&format+1), (void (*))"\x16\xC0\x4E\x75", buffer);
  28. }
  29.  
  30. #endif /* AMIGA */
  31.  
  32.  
  33. /*************************************************************************
  34.  * InitSystem() - Called from main() to initilise and check any system
  35.  *  options or dependancies.
  36.  */
  37.  
  38. int InitSystem( void )
  39. {
  40. #ifdef AMIGA
  41.     if( (((struct Library *)DOSBase)->lib_Version >= 36) &&
  42.         (((struct Library *)SysBase)->lib_Version >= 36) )
  43.         return( 1 );
  44.     else
  45.         return( 0 );
  46. #else
  47.     return( 1 );
  48. #endif
  49. }
  50.  
  51.  
  52. /*************************************************************************
  53.  * FreeSystem() - Called from main() to delalocate anything allocated
  54.  *  by InitSystem.
  55.  */
  56.  
  57. void FreeSystem( void )
  58. {
  59. }
  60.  
  61.  
  62. /*************************************************************************
  63.  * GetChunkerArgs() - Parse command line arguments for Chunker
  64.  */
  65.  
  66. #define ARG_CSOURCE argv[1]
  67. #define ARG_CDEST argv[2]
  68. #define ARG_CSIZE argv[3]
  69. #define NUM_CARGS 4
  70.  
  71. struct Args *GetChunkerArgs(int argc, char **argv)
  72. {
  73.     struct Args *args = NULL;
  74. #ifdef AMIGA
  75. #define CHUNKER_TEMP "SOURCE/A,DESTBASENAME/A,SIZE/N/A"
  76. #define OPT_CSOURCE 0
  77. #define OPT_CDEST 1
  78. #define OPT_CSIZE 2
  79. #define OPT_CMAX 3
  80.     if( args = (struct Args *)mmalloc(sizeof(struct Args)) )
  81.     {
  82.         STRPTR argsa[OPT_CMAX] = {0, 0, 0};
  83.         
  84.         if( args->arg_RAHandle = ReadArgs(CHUNKER_TEMP, (LONG *)&argsa, NULL) )
  85.         {
  86.             args->arg_Filename = argsa[OPT_CSOURCE];
  87.             args->arg_Basename = argsa[OPT_CDEST];
  88.             args->arg_Size = *((unsigned long *)argsa[OPT_CSIZE]);
  89.         } else
  90.         {
  91.             mfree((char *)args);
  92.             args = NULL;
  93.             PrintFault(IoErr(), "Chunker");
  94.         }
  95.     }
  96. #else
  97.     if( argc == NUM_CARGS )
  98.     {
  99.         if( atol(ARG_CSIZE) )
  100.         {
  101.             if( args = (struct Args *)mmalloc(sizeof(struct Args)) )
  102.             {
  103.                 args->arg_Filename = ARG_CSOURCE;
  104.                 args->arg_Basename = ARG_CDEST;
  105.                 args->arg_Size = atol(ARG_CSIZE);
  106.             }
  107.         } else
  108.             mprintf("3rd argument must be an integer\n");
  109.     } else
  110.         mprintf("Usage:\n chunker <file> <basename> <size>\n");
  111. #endif    
  112.     return( args );
  113. }
  114.  
  115.  
  116. /*************************************************************************
  117.  * FreeChunkerArgs() - Free Arguments for chunker
  118.  */
  119.  
  120. void FreeChunkerArgs(struct Args *args)
  121. {
  122.     if( args )
  123.     {
  124. #ifdef AMIGA
  125.         if( args->arg_RAHandle )
  126.             FreeArgs(args->arg_RAHandle);
  127. #endif
  128.         mfree((char *)args);
  129.     }    
  130. }
  131.  
  132.  
  133. /*************************************************************************
  134.  * GetDeChunkArgs() - Parse command line arguments for dechunk
  135.  */
  136.  
  137. #define ARG_DDEST argv[1]
  138. #define ARG_DSOURCE argv[2]
  139. #define NUM_DARGS 3
  140.  
  141. struct Args *GetDeChunkArgs(int argc, char **argv)
  142. {
  143.     struct Args *args = NULL;
  144. #ifdef AMIGA
  145. #define DECHUNK_TEMP "DESTINATION/A,BASENAME/A"
  146. #define OPT_DDEST 0
  147. #define OPT_DBASE 1
  148. #define OPT_DMAX 2
  149.     if( args = (struct Args *)mmalloc(sizeof(struct Args)) )
  150.     {
  151.         STRPTR argsa[OPT_DMAX] = {0, 0};
  152.         
  153.         if( args->arg_RAHandle = ReadArgs(DECHUNK_TEMP, (LONG *)&argsa, NULL) )
  154.         {
  155.             args->arg_Filename = argsa[OPT_DDEST];
  156.             args->arg_Basename = argsa[OPT_DBASE];
  157.         } else
  158.         {
  159.             mfree((char *)args);
  160.             args = NULL;
  161.             PrintFault(IoErr(), "DeChunk");
  162.         }
  163.     }
  164. #else
  165.     if( argc == NUM_DARGS )
  166.     {
  167.         if( args = (struct Args *)mmalloc(sizeof(struct Args)) )
  168.         {
  169.             args->arg_Filename = ARG_DDEST;
  170.             args->arg_Basename = ARG_DSOURCE;
  171.         }
  172.     } else
  173.         mprintf("Usage:\n dechunk <outputfile> <basename>");
  174. #endif    
  175.     return( args );
  176. }
  177.  
  178.  
  179. /*************************************************************************
  180.  * FreeDeChunkArgs() - Free Arguments for chunker
  181.  */
  182.  
  183. void FreeDeChunkArgs(struct Args *args)
  184. {
  185.     if( args )
  186.     {
  187. #ifdef AMIGA
  188.         if( args->arg_RAHandle )
  189.             FreeArgs(args->arg_RAHandle);
  190. #endif
  191.         mfree((char *)args);
  192.     }    
  193. }
  194.